'use strict';

const Controller = require('egg').Controller;

class TestController extends Controller {
  constructor(ctx) {
    super(ctx);
  }

  // 加解密测试
  async test() {
    const cryptoJS = require('../extend/cryptoJS');
    let secretKey = cryptoJS.secretKey();
    let aesDecryptOrEncrypt = cryptoJS.aesEncrypt([{a: 123}], secretKey);
    this.ctx.body = aesDecryptOrEncrypt;
    console.log(cryptoJS.aesDecrypt(aesDecryptOrEncrypt, secretKey));
  }

  async wbDelete() {
    try {
      let url = 'https://api.weibo.cn/2/profile/statuses/tab?gsid=_2A25z1zyIDeRxGedO61YU9yrPzz2IHXVuxTdArDV6PUJbkdAKLXn4kWpNJrNr3SfhjyVQI_esN088fUBxZ2h3nnyr&sensors_mark=0&wm=3333_2001&launchid=10000365--x&sensors_is_first_day=false&from=10A4093010&b=0&c=iphone&networktype=wifi&skin=default&v_p=82&s=a0a32b8f&v_f=1&sensors_device_id=79B6F2CE-707D-468F-8629-A9B945BBB64C&lang=zh_CN&sflag=1&ua=iPhone11,8__weibo__10.4.0__iphone__os13.4.1&ft=11&aid=01A-fShTlvc8nqrUNhoewR1fPkoFSlnEZY_4hSXNbJA0iXJ80.&oriuicode=10000011&orifid=1005051004574341_-_new&count=20&luicode=10000011&containerid=2304131004574341_-_WEIBO_SECOND_PROFILE_WEIBO&fid=2304131004574341_-_WEIBO_SECOND_PROFILE_WEIBO&uicode=10000011&need_head_cards=0&need_new_pop=1&page=' + 1 + '&lfid=1005051004574341_-_new&moduleID=pagecard&page_interrupt_enable=0';
      let result;
      result = await this.ctx.curl(url, {
        method: 'get',
        dataType: 'json'
      });
      const {ctx} = this
      console.log(result.res.data.cards)
      let ids = [];
      result.res.data.cards.map((item) => {
        if (item.mblog) {
          // console.log(item.mblog.idstr)
          ids.push(item.mblog)
        }
      });
      // console.log(ids)
      for (let i = 0; i < ids.length; i++) {
        // if (ids[i].text.search("白敬亭") === 1 ) {
        setTimeout(async function () {
          // console.log(ids[i].text)
          console.log(ids[i].idstr)
          let delResult;
          // let delUrl = 'https://mapi.weibo.com/2/statuses/destroy?gsid=_2A25zmEeWDeRxGeRK6lYX8CnFzTuIHXVuDNxerDV6PUJbkdAKLW3HkWpNU3HiIgYktOeORvTiIcJu4uvqFoN0wskA&sensors_mark=0&wm=3333_2001&sensors_is_first_day=false&from=10A3293010&b=0&c=iphone&networktype=wifi&skin=default&v_p=82&v_f=1&s=a19e4178&sensors_device_id=79B6F2CE-707D-468F-8629-A9B945BBB64C&lang=zh_CN&sflag=1&ua=iPhone11,8__weibo__10.3.2__iphone__os13.3.1&ft=11&aid=01A-fShTlvc8nqrUNhoewR1fPkoFSlnEZY_4hSXNbJA0iXJ80.&launchid=10000365--x';
          let delUrl = 'https://api.weibo.cn/2/statuses/destroy?gsid=_2A25z1zyIDeRxGedO61YU9yrPzz2IHXVuxTdArDV6PUJbkdAKLXn4kWpNJrNr3SfhjyVQI_esN088fUBxZ2h3nnyr&sensors_mark=0&wm=3333_2001&launchid=10000365--x&sensors_is_first_day=false&from=10A4093010&b=0&c=iphone&networktype=wifi&skin=default&v_p=82&s=a0a32b8f&v_f=1&sensors_device_id=79B6F2CE-707D-468F-8629-A9B945BBB64C&lang=zh_CN&sflag=1&ua=iPhone11,8__weibo__10.4.0__iphone__os13.4.1&ft=11&aid=01A-fShTlvc8nqrUNhoewR1fPkoFSlnEZY_4hSXNbJA0iXJ80.';
          delResult = await ctx.curl(delUrl, {
            method: 'POST',
            data: {
              id: ids[i].idstr
            },
            dataType: 'json',
            // timeout: 1600,
          });
          console.log(ids[i].idstr, '删除' + delResult.res.statusMessage)
        }, i * 10);

        // }
      }

      this.ctx.status = 200;
      this.ctx.body = {
        code: 0,
        success: true,
        data: '成功'
      };
    } catch (e) {
      this.ctx.body = {
        code: 403,
        message: 'Authing auth failed',
        error: e,
      }
    }

  }
}


module.exports = TestController;
